#include "Buoyancy.h"

void Buoyancy::updateForce(Particle* particle, float frameTime)
{
	// Calculate the submersion depth.
	float depth = particle->position.y;

	// Check if we're out of the water.
	if (depth >= waterHeight + maxDepth) return;
	D3DXVECTOR3 force(0, 0, 0);

	// Check if we're at maximum depth.
	if (depth <= waterHeight - maxDepth)
	{
		force.y = liquidDensity * volume;
		particle->force += force;
		return;
	}

	// Otherwise we are partly submerged.
	force.y = liquidDensity * volume *
		(depth - maxDepth - waterHeight) / 2 * maxDepth;
	particle->force += force;
}